<template>
	<view class="box">
		<view class="bg"></view>
		<view class="list">
			<!-- 订单状态 -->
			<view class="state card">
				<view class="state-text f32">{{state_name}}</view>
				<view class="state-desc f24 c999">{{state_desc}}</view>
			</view>
			<!-- 买手 -->
			<view class="msg card" v-if="info.RefundInfo.buyer">
				<view class="msg-title f28 fw-bt">
					<view class="bold">买手信息</view>
				</view>
				<view class="msg-buy fw-bt">
					<view>
						<view class="f26">{{info.RefundInfo.buyer.real_name}}</view>
						<view class="f22 c999 rm">{{info.RefundInfo.buyer.phone}}</view>
					</view>
					<view class="call-btn" @click="call(info.RefundInfo.buyer.phone)">电话联系</view>
				</view>
			</view>
			<!-- 骑手信息 -->
			<view class="msg card" v-if="info.RefundInfo.rider">
				<view class="msg-title f28 fw-bt">
					<view class="bold">骑手信息</view>
				</view>
				<view class="msg-buy fw-bt">
					<view>
						<view class="f26">{{info.RefundInfo.rider.real_name}}</view>
						<view class="f22 c999 rm">{{info.RefundInfo.rider.phone}}</view>
					</view>
					<view class="call-btn" @click="call(info.RefundInfo.rider.phone)">电话联系</view>
				</view>
			</view>
			<!-- 订单信息 -->
			<view class="order card">
				<view class="title  fw-bt">
					<view class="f28 bold">{{info.RefundInfo.market.mar_name}}-{{info.RefundInfo.merchant.mer_name}}
					</view>
					<view class="f26 f-w" @click="call(info.RefundInfo.merchant.mer_phone)">
						<view class="title-img f-w">
							<image src="https://jw.xzsw2021.com/static/order/icon_201@2x.png" mode=""></image>
						</view>
						<view>联系商家</view>
					</view>
				</view>
				<view class="order-list">
					<view class="shop" v-for="(item,index) of info.refundProduct" :key="index">
						<view class="f-w">
							<view class="shop-msg f-w">
								<image :src="item.product.cart_info.productAttr.image" mode=""></image>
							</view>
							<view class="shop-right">
								<view class="one fw-bt">
									<view class="shop-name f28 c333 hide-line">
										{{item.product.cart_info.product.store_name}}
										<view class="f-w shop-name f28" style="color: red;">
											{{item.product.cart_info.productAttr.sku||';;;;'}}
										</view>
									</view>
									<view class="f-w">
										<view class="price1" v-if="item.old_price">
											￥{{item.product.cart_info.productAttr.ot_price}}</view>
										<view class="price2 f28 bold">￥{{item.product.product_price}}</view>
									</view>
								</view>
								<view class="two hide-line">{{item.desc}}</view>
								<!-- 数量 -->
								<view class="three">×{{item.product.product_num}}</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<!-- 配送信息 -->
			<view class="ps-msg card">
				<view class="title">配送信息</view>
				<view class="p2">
					<view class="flex">
						<view class="label">收货地址:</view>
						<view>
							{{`${info.order.groupOrder.real_name||''} ${info.order.groupOrder.user_phone||''} ${info.order.groupOrder.user_address||''}`}}
						</view>
						<!-- <view>柠檬张 18545147899 重庆市南岸区弹子石 街道，国际商务大厦B座1401</view> -->
					</view>
					<view class="f-w">
						<view class="label">配送时间:</view>
						<view class="orange">
							{{info.order.groupOrder.delivery_day}}{{info.order.groupOrder.delivery_time_scope}}
						</view>
					</view>
				</view>
			</view>
			<!-- 申请原因 -->
			<view class="card note">
				<view class="title">申请原因</view>
				<view class="p2">
					{{info.mark}}
				</view>
			</view>
			<!-- 申请凭证 -->
			<view class="card note" v-if="info.refundProduct">
				<view class="title">申请凭证</view>
				<view class="imgs">
					<template v-for="(item,index) in info.images">
						<image :src="item" mode=""></image>
					</template>
				</view>
			</view>
			<!-- 订单信息 -->
			<view class="order-msg card">
				<view class="title">订单信息</view>
				<view class="p2">
					<view class="2 f-w">
						<view class="label">退款编号:</view>
						<view class="fw-bt">
							<view>{{info.refund_order_sn}}</view>
							<view class="orange" @click="copy(info.refund_order_sn)">复制</view>
						</view>
					</view>
					<view class="f-w">
						<view class="label">申请时间:</view>
						<view>{{info.create_time}}</view>
					</view>
					<view class="f-w liyou">
						<view class="label">退/换货理由:</view>
						<view>{{info.refund_message}}</view>
					</view>
				</view>
			</view>
		</view>
		<!-- 删除订单-->
		<view class="bottom" v-if="state==4">
			<view @click="delOrder">删除订单</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				state: 6, ////1.退/换货中 2.退/换货完成 3.退/换货失败 4.退款失败 5.退款成功 6.退/换货/退款处理中
				state_desc: '', //状态说明
				name: '老粉',
				mobile: '131313',
				showMore: false, //展示全部
				range: true, //配送范围
				djs: '', //倒计时
				order: {
					end_time: '2022-02-15 14:37',
					time: '',
				},
				rider: {
					id: 32,
					name: '梁鹏',
					mobile: '18357457899',
				}, //骑手信息
				buy_user: {
					id: 33,
					name: '张太太',
					img: 'https://jw.xzsw2021.com/static/index/tu_18@2x.png',
					mobile: '18357457896',
					shop_name: '南岸区弹子石菜市场'
				}, //买手信息
				is_dixian: true, //是否抵现
				pay_wx: true, //支付方式 1微信 0余额
				pay_yue: false,
				note1: '', //待用备注
				note: '', //备注
				date_list: ['今天', '明天'], //
				active: 0, //
				active2: 0, //
				times_list: [{
						name: '立即送达10:00-12:00',

					},
					{
						name: '12:00-14:00',

					},
					{
						name: '14:00-16:00',
					},
					{
						name: '16:00-18:00',
					},
					{
						name: '18:00-20:00',
					},
					{
						name: '20:00-22:00',
					}
				], //送达时间列表
				temp: null, //
				// u-radio-group的v-model绑定的值如果设置为某个radio的name，就会被默认选中
				radiovalue1: '商品无货',
				info: {}
			}
		},
		watch: {
			address(n, o) {
				console.log(n, "旧：", o);
				if (n) {
					// 当新值存在时，检测是否超出配送范围
					this.range = false
					if (!this.range) {
						this.$showToast('配送地址超出范围，请重新选择')
					}
				}
			}
		},
		computed: {

			state_name() {
				console.log(this.info)
				let statsInfo = ''
				switch (this.info.refund_type) {
					case 1:
						statsInfo = '退款'
						break;
					case 2:
						statsInfo = '退款退货'
						break
					default:
						statsInfo = '换货'
				}
				// let statsInfo = this.info.refund_type == 1 ? '退款' : (this.info.refund_type == 2 ? '退款退货' : '换货')
				if (this.info.status == 1 || this.info.status == 2) {
					this.state_desc = '您的售后订单正在处理中，请耐心等待';
					return statsInfo + '处理中'
				} else if (this.info.status == 3) {
					this.state_desc = '您的售后订单已处理完成';
					return statsInfo + '完成'
				} else if (this.info.status == -1) {
					this.state_desc = this.info.fail_message;
					return statsInfo + '失败'
				} else if (this.info.status == 0) {
					this.state_desc = '您的售后订单正在处理中，请耐心等待';
					return statsInfo + '待审核'
				} else {
					this.state_desc = '您的售后订单正在处理中，请耐心等待';
					return statsInfo + '待审核'
				}


			}
		},
		onLoad(e) {
			this.id = e.id
			this.timer();
			// this.$refs.popup8.open();
		},
		onShow() {
			this.getDetail()
		},
		methods: {
			// 倒计时
			timer() {
				this.temp = setInterval(() => {
					this.djs = this.$countTime2(this.order.end_time);
					if (!this.djs) {
						clearInterval(this.temp);
						// 发送取消请求
						this.djs = ''
					}
				}, 1000)
				console.log('倒计时', this.djs);
			},
			// 关闭说明
			pop2Close() {
				this.$refs.popup2.close()
			},
			// 打开说明
			openPop2(index) {
				this.$refs.popup2.open();
				if (index == 1) {
					console.log('积分底线说明');
				}
				if (index == 2) {
					console.log('红包说明');
				}
				if (index == 3) {
					console.log('配送红包说明');
				}
				if (index == 4) {
					console.log('优惠券说明');
				}
			},
			// 拨打电话
			call(num) {
				uni.makePhoneCall({
					phoneNumber: String(num),
					success() {

					},
					fail(res) {
						console.log(res);
					}
				})
			},
			// 显示商品
			showAll() {
				this.showMore = !this.showMore;

			},
			// 复制订单号
			copy(value) {
				this.$copy(value)
			},
			getDetail() {
				let that = this
				this.$request("refund/detail/" + this.id, {}, 'GET').then(res => {
					this.info = res.data


				})
			},
			// 取消订单
			cancelOrder(id) {
				// uni.showModal({
				// 	content: '确认取消此订单吗？',
				// 	confirmColor: '#F31E1E',
				// 	success(res) {
				// 		if (res.confirm) {
				// 			console.log('取消订单');
				// 		}
				// 	}
				// })
				console.log('取消订单');
				this.$refs.popup5.open()
			},
			// 确认取消
			pop5Sure() {
				this.$refs.popup5.close();
				this.$refs.popup6.open();
			},
			// 关闭取消弹窗
			pop5Close() {
				this.$refs.popup5.close();
			},
			groupChange(n) {
				console.log('groupChange', n);
			},
			radioChange(n) {
				console.log('radioChange', n);
			},
			// 确认取消订单原因
			pop6Sure() {
				this.$refs.popup6.close();
				this.$showToast('取消成功')
			},
			// 关闭取消订单原因弹窗
			pop6Close() {
				this.$refs.popup6.close();
			},
			// 删除订单
			delOrder(id) {
				console.log('删除订单');
			},
			// 修改地址
			updateAddressOrder(id) {
				console.log('修改地址');
				uni.navigateTo({
					url: '/pages/client/address-choose/address-choose?orgin=1'
				})
			},
			// 去支付
			goPayOrder(id) {
				console.log('去支付');
				this.$refs.popup4.open()
			},
			// 关闭支付弹窗
			pop4Close() {
				this.$refs.popup4.close()
			},
			// 付款
			pay() {
				this.$refs.popup4.close()
			},
			// 修改配送时间
			updateDateOrder(id) {
				console.log('修改配送时间');
				this.$refs.popup3.open()
			},
			// 切换配送时间
			checkDate(index) {
				this.active = index
			},
			// 选择配送时间
			chooseTimes(index) {
				this.active2 = index;
				this.order.time = this.date_list[this.active] + this.times_list[this.active2].name
				this.$refs.popup3.close();
			},
			// 关闭配送时间弹窗
			pop3Close() {
				this.$refs.popup3.close()
			},
			// 催单
			reminderOrder(id) {
				console.log('催单');
				this.$refs.popup7.open()
			},
			// 关闭催单弹窗
			pop7Close() {
				this.$refs.popup7.close()
			},
			// 去评价
			goEvaluation(id) {
				console.log('去评价');
			},
			// 申请售后
			goAfterSales(id) {
				console.log('申请售后');
			},
			// 再来一单
			againOrder(id) {
				console.log('再来一单');
				uni.navigateTo({
					url: '/pages/client/order/order-sure/order-sure?isagain=1'
				})
			},
			// 申请开票
			applyTicket(id) {
				console.log('申请开票');
			},
			// 开票历史
			ticketHistory(id) {
				console.log('开票历史');
			},
			// 差价说明
			ChajiaDesc(id) {
				this.$refs.popup8.open();
			},
			// 关闭差价弹窗
			pop8Close() {
				this.$refs.popup8.close();
			}
		}
	}
</script>
<style>
	page {
		background-color: #F5F5F5;
	}
	.imgs {
		box-sizing: border-box;
		padding: 20rpx 20rpx;
		display: flex;
		flex-wrap: wrap;
		padding-bottom: 0;
	}
	
	.imgs>image {
		width: 200rpx;
		height: 200rpx;
		border-radius: 8rpx;
		margin-left: 20rpx;
		/* background: #18BC37; */
		margin-bottom: 20rpx;
	}
</style>
<style lang="scss" scoped>
	.box {
		padding-bottom: 32rpx;
		position: relative;

		.showColor {
			font-weight: bold;
			color: #F45E14;
		}

		.red {
			color: #F83535;
		}

		.bg {
			left: 0;
			top: 0;
			position: absolute;
			width: 750rpx;
			height: 210rpx;
			background: #109C7A;
		}

		.tag {
			margin-left: 15rpx;
			flex-shrink: 0;
			width: 11rpx;
			height: 20rpx;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.list {
			position: relative;
			overflow: hidden;
			z-index: 2;

			&>view:nth-child(1) {
				margin: 50rpx auto 0;
			}
		}

		.card {
			margin: 0 auto;
			width: 690rpx;
			padding: 0 30rpx;
			background: #FFFFFF;
			border-radius: 20rpx;
			box-sizing: border-box;
		}

		.delColor {
			color: #999 !important;
		}

		.state {
			margin: 50rpx auto 0;
			padding: 30rpx 40rpx 40rpx;
			text-align: center;
			box-sizing: border-box;

			.state-desc {
				margin: 16rpx 0 28rpx;
			}

			.state-btn {
				&>view {
					flex-shrink: 0;
					width: 190rpx;
					height: 70rpx;
					line-height: 70rpx;
					font-size: 24rpx;
					text-align: center;
					background: #FFFFFF;
					border: 1rpx solid #CCCCCC;
					border-radius: 10rpx;
				}

				&>view:not(:last-child) {
					margin-right: 20rpx;
				}

				.state1 {
					background: #F83535;
					border: 1rpx solid #F83535;
					color: #fff;
				}

				.state2 {
					background: linear-gradient(64deg, #2BCCA5, #22B591);
					box-shadow: 0rpx 4rpx 6rpx 0rpx rgba(20, 187, 146, 0.4);
					border: 1rpx solid #14BB92;
					color: #fff;
				}

				.state3 {
					background: #F5F5F5;
					border: 1rpx solid #F5F5F5;
					color: #999;
				}
			}
		}

		.msg {
			padding: 0;
			margin-top: 20rpx;

			.msg-title {
				padding: 28rpx 30rpx;
				border-bottom: 1rpx solid #eee;
			}

			.msg-buy {
				padding: 20rpx 30rpx 30rpx;

				.call-btn {
					padding: 6rpx 12rpx;
					font-size: 26rpx;
					border: 1rpx solid #EEEEEE;
					border-radius: 22rpx;
				}

				.rm {
					margin-top: 10rpx;
				}

				.msg-buy1 {
					flex-shrink: 0;
					width: 70rpx;
					height: 70rpx;

					image {
						width: 100%;
						height: 100%;
						border-radius: 50%;
					}
				}

				.msg-buy2 {
					flex: 1;
					margin-left: 14rpx;

					&>view:nth-child(1) {
						margin-bottom: 8rpx;
					}
				}
			}

		}

		.order {
			padding: 0 0 30rpx;
			margin-top: 20rpx;

			&>view {
				padding: 0 30rpx;
			}

			.title {
				padding: 26rpx 30rpx;
				border-bottom: 1rpx solid #eee;

				&>view:nth-child(2) {
					color: #109C7A;
				}

				.title-img {
					margin-right: 10rpx;
					width: 27rpx;
					height: 27rpx;

					image {
						width: 100%;
						height: 100%;
					}
				}
			}

			.order-list {
				margin-top: 5rpx;

				&>view:not(:first-child) {
					border-top: 1rpx solid #eee;
				}

				.shop {
					position: relative;
					transition: 3s;
					padding: 23rpx 0;

					.shop-msg {
						width: 110rpx;
						height: 100rpx;
						flex-shrink: 0;

						image {
							width: 100%;
							height: 100%;
							border-radius: 12rpx;
						}
					}

					.shop-right {
						margin-left: 15rpx;
						flex: 1;
						min-height: 110rpx;

						.one {
							.shop-name {
								width: 308rpx;
							}

							.price1 {
								font-size: 24rpx;
								text-decoration: line-through;
								color: #999999;
							}

							.price2 {
								margin-left: 30rpx;
							}
						}

						.two,
						.three {
							font-size: 22rpx;
							color: #666;
						}

						.two {
							margin: 6rpx 0;
							height: 28rpx;
						}
					}
				}
			}
		}

		.orange {
			color: #F45E14;
		}

		// 配送信息
		.ps-msg,
		.order-msg,
		.note {
			margin: 20rpx auto 0;
			padding: 0;

			.title {
				padding: 26rpx 30rpx;
				border-bottom: 1rpx solid #eee;
				font-size: 28rpx;
				font-weight: bold;
			}

			.p2 {
				&>view:nth-child(1) {
					margin-bottom: 25rpx;
				}

				padding: 26rpx 30rpx;
				font-size: 26rpx;

				.label {
					flex-shrink: 0;
					width: 130rpx;
					font-size: 26rpx;
				}

				.liyou {
					margin-top: 25rpx;

					.label {
						width: 160rpx;
					}
				}

				.label+view {
					flex: 1;
					line-height: 40rpx;
				}
			}
		}

		// 备注
		.note {
			.p2 {
				line-height: 44rpx;
			}
		}

		// 底部删除按钮
		.bottom {
			position: fixed;
			left: 0;
			bottom: 0;
			width: 750rpx;
			height: 120rpx;
			background: #FFFFFF;
			z-index: 101;
			text-align: right;
			border-top: 1rpx solid #eee;
			box-sizing: border-box;

			&>view {
				margin: 25rpx 60rpx 25rpx;
				display: inline-block;
				width: 190rpx;
				height: 70rpx;
				line-height: 70rpx;
				text-align: center;
				font-size: 26rpx;
				background: #FFFFFF;
				border: 1rpx solid #CCCCCC;
				border-radius: 10rpx;
			}
		}
	}
</style>
